package com.jdyfy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jdyfy.dto.RoleUserCountDTO;
import com.jdyfy.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    /**
     * 根据用户名查询员工
     * @param username
     * @return
     */
    @Select("select * from users where username = #{username}")
    User getByUsername(String username);

    /**
     * 根据id查询员工
     * @param id
     * @return
     */
    @Select("select * from users where user_id = #{id}")
    User getByUserId(Long id);

    /**
     * 查询所有员工信息
     * @return
     */
    @Select("SELECT * from users")
    List<User> findAll();

    /**
     * 新增员工
     * @param user
     * @return
     */
    @Insert("INSERT into users(username,password,name,phone_number,department,status,avatar,address,email,role_id) VALUES (#{username},#{password}," +
            " #{name},#{phoneNumber},#{department},#{status},#{avatar},#{address},#{email},#{roleId})")
    int insert(User user);

    /**
     * 修改员工信息
     * @param user
     * @return
     */
    int update(User user);

    /**
     * 根据角色id查询员工
     * @param roleId
     * @return
     */
    @Select("SELECT * FROM users WHERE role_id = #{roleId}")
    List<User> getUsersByRoleId(Long roleId);

    /**
     * 根据员工姓名查询员工
     * @param name
     * @return
     */
    @Select("select * from users where name = #{name}")
    User getByName(String name);

    List<RoleUserCountDTO> getUserCountByRole();

}
